#include"comm.hpp"


int main()
{
  //命名管道
  bool r=Makefifo();
  if(!r)
    return 1;

  //创建共享内存
  key_t key=Getkey();
  std::cout<<"key: "<<ToHex(key)<<std::endl;
  int shmid =Creatshmid(key);
  std::cout<<"shmid："<<shmid<<std::endl;
  //挂起
  char* s=(char*)shmat(shmid,nullptr,0);
  int fd=open(filename.c_str(),O_RDONLY);

  //TODO
  //读取
  while(true)
  {
    //等待
    int code=0;
    ssize_t n=read(fd,&code,sizeof(code));

    std::cout<<"共享区的内容： "<<s<<std::endl;
  }

  //取消关联
  shmdt(s);
  //从OS中删除
  shmctl(shmid,IPC_RMID,nullptr);
  return 0;
}
